#!/bin/bash
# USAGE:
#	pn2rs processName 
#	pnr2rs -f processName
#
# DESCRIPTION:
#  PN2RS is an internal ADORE function.  
#  It outputs the resultfile section name or the 
#  result file name for the given processName.
#
# INPUT:
#  -f: Flag for filename. If present corresponding filename
#	is returned. 
#  processName: Doris step to lookup.
#  
# OUTPUT:
#  Name of the section in doris result file.

#[ "$1" == "m_readfiles" ] && echo readfiles
#[ "$1" == "s_readfiles" ] && echo readfiles
#[ "$1" == "coarseorb"   ] && echo coarse_orbits
#[ "$1" == "demassist"   ] && echo dem_assist
#[ "$1" == "subtrrefpha"   ] && echo subtr_refphase
#[ "$1" == "dinsar"  ] && echo dinsar
#[ "$1" == "m_porbits"  ] && echo precise_orbits
#[ "$1" == "s_porbits"  ] && echo precise_orbits
#[ "$1" == "coarsecorr"  ] && echo coarse_correl
#[ "$1" == "coregpm"  ] && echo comp_coregpm
#[ "$1" == "comprefdem"  ] && echo comp_refdem
#[ "$1" == "slant2h"  ] && echo slant2h
#[ "$1" == "m_crop"  ] && echo crop
#[ "$1" == "s_crop"  ] && echo crop
#[ "$1" == "m_filtazi"  ] && echo filt_azi
#[ "$1" == "resample"  ] && echo resample
#[ "$1" == "subtrrefdem"  ] && echo subtr_refdem
#[ "$1" == "geocode"  ] && echo geocoding
#[ "$1" == "m_simamp"  ] && echo sim_amplitude
#[ "$1" == "s_filtazi"  ] && echo filt_azi
#[ "$1" == "filtrange"  ] && echo filt_range
#[ "$1" == "coherence"  ] && echo coherence
#[ "$1" == "m_timing"  ] && echo master_timing
#[ "$1" == "fine"  ] && echo fine_coreg
#[ "$1" == "interfero"  ] && echo interfero
#[ "$1" == "filtphase"  ] && echo filtphase
#[ "$1" == "m_ovs"  ] && echo oversample 
#[ "$1" == "s_ovs"  ] && echo oversample
#[ "$1" == "reltiming"  ] && echo timing_error
#[ "$1" == "comprefpha"  ] && echo comp_refphase
#[ "$1" == "unwrap"  ] && echo unwrap
function getName(){
case "${1}" in
  m_readfiles ) echo readfiles      ;;
  s_readfiles ) echo readfiles      ;;
  coarseorb   ) echo coarse_orbits  ;;
  demassist   ) echo dem_assist     ;;
  subtrrefpha ) echo subtr_refphase ;;
  dinsar      ) echo dinsar         ;;
  m_porbits   ) echo precise_orbits ;;
  s_porbits   ) echo precise_orbits ;; 
  coarsecorr  ) echo coarse_correl  ;;
  coregpm     ) echo comp_coregpm   ;;
  comprefdem  ) echo comp_refdem    ;;
  slant2h     ) echo slant2h        ;;
  m_crop      ) echo crop           ;;
  s_crop      ) echo crop           ;;
  m_filtazi   ) echo filt_azi       ;; 
  resample    ) echo resample       ;;
  subtrrefdem ) echo subtr_refdem   ;; 
  geocode     ) echo geocoding      ;;
  m_simamp    ) echo sim_amplitude  ;;
  s_filtazi   ) echo filt_azi       ;;
  filtrange   ) echo filt_range     ;;
  coherence   ) echo coherence      ;;
  m_timing    ) echo master_timing  ;;
  fine        ) echo fine_coreg     ;;
  interfero   ) echo interfero      ;;
  filtphase   ) echo filtphase      ;;
  m_ovs       ) echo oversample     ;;
  s_ovs       ) echo oversample     ;;
  reltiming   ) echo timing_error   ;;
  comprefpha  ) echo comp_refphase  ;;
  unwrap      ) echo unwrap         ;;
  ci2	      ) echo complex_short  ;;
  cr4	      ) echo complex_real4  ;;
  i2          ) echo short	    ;;
  r4          ) echo real4          ;;
  *           ) echo ${1}           ;;
esac
}

function getFile(){
case "${1}" in
  m_readfiles ) echo ${m_resfile}   ;;
  s_readfiles ) echo ${s_resfile}   ;;
  coarseorb   ) echo ${i_resfile}   ;;
  demassist   ) echo ${i_resfile}   ;;
  subtrrefpha ) echo ${i_resfile}   ;;
  dinsar      ) echo ${i_resfile}   ;;
  m_porbits   ) echo ${m_resfile}   ;;
  s_porbits   ) echo ${s_resfile}   ;; 
  coarsecorr  ) echo ${i_resfile}   ;;
  coregpm     ) echo ${i_resfile}   ;;
  comprefdem  ) echo ${i_resfile}   ;;
  slant2h     ) echo ${i_resfile}   ;;
  m_crop      ) echo ${m_resfile}   ;;
  s_crop      ) echo ${s_resfile}   ;;
  m_filtazi   ) echo ${m_resfile}   ;;
  resample    ) echo ${s_resfile}   ;;
  subtrrefdem ) echo ${i_resfile}   ;;
  geocode     ) echo ${i_resfile}   ;;
  m_simamp    ) echo ${m_resfile}   ;;
  s_filtazi   ) echo ${s_resfile}   ;;
  filtrange   ) echo ${i_resfile}   ;;
  coherence   ) echo ${i_resfile}   ;;
  m_timing    ) echo ${m_resfile}   ;;
  fine        ) echo ${i_resfile}   ;;
  interfero   ) echo ${i_resfile}   ;;
  filtphase   ) echo ${i_resfile}   ;;
  m_ovs       ) echo ${m_resfile}   ;;
  s_ovs       ) echo ${s_resfile}   ;;
  reltiming   ) echo ${i_resfile}   ;;
  comprefpha  ) echo ${i_resfile}   ;;
  unwrap      ) echo ${i_resfile}   ;;
  *           ) echo ${1}           ;;
esac
}
#main
if [[ "${1}" != "-f" ]];then
  getName $@
else
  getFile ${2}
fi
